package com.hxc.shop.controller;

import com.hxc.shop.common.ResultVO;
import com.hxc.shop.service.AddressService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/address")
@CrossOrigin
@Api(tags = {"购物地址数据处理"})
public class AddressController {
    @Resource
    private AddressService addressService;

    @ApiOperation("查找购物地址列表")
    @GetMapping("/findGoodsAddress")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userName",value = "用户名",required = true,paramType = "String")
    })
    @Transactional(rollbackFor = Exception.class)
    public ResultVO findGoodsAddress(@RequestParam("userName")String userName){
        return addressService.findGoodsAddress(userName);
    }

    @ApiOperation("添加购物地址")
    @GetMapping("/addGoodsAddress")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userName",value = "用户名",required = true,paramType = "String"),
            @ApiImplicitParam(name = "goodsAddress",value = "购物地址",required = true,paramType = "String"),
    })
    @Transactional(rollbackFor = Exception.class)
    public ResultVO addGoodsAddress(@RequestParam("userName")String userName,@RequestParam("goodsAddress")String goodsAddress){
        return addressService.addGoodsAddress(userName,goodsAddress);
    }

    @ApiOperation("删除购物地址")
    @GetMapping("/deleteGoodsAddress")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "购物地址编号",required = true,paramType = "Integer"),
    })
    @Transactional(rollbackFor = Exception.class)
    public ResultVO deleteGoodsAddress(@RequestParam("id")Integer id){
        return addressService.deleteGoodsAddress(id);
    }

    @ApiOperation("修改购物地址")
    @GetMapping("/changeGoodsAddress")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "购物地址编号",required = true,paramType = "Integer"),
            @ApiImplicitParam(name = "userName",value = "用户名",required = true,paramType = "String"),
            @ApiImplicitParam(name = "address",value = "购物地址",required = true,paramType = "String"),
    })
    @Transactional(rollbackFor = Exception.class)
    public ResultVO changeGoodsAddress(@RequestParam("id")Integer id,@RequestParam("userName")String userName,@RequestParam("address")String address){
        return addressService.changeGoodsAddress(id,userName,address);
    }

    @ApiOperation("根据购物地址编号和用户名获取购物地址")
    @GetMapping("/getGoodsAddressByIdAndUserName")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "购物地址编号",required = true,paramType = "Integer"),
            @ApiImplicitParam(name = "userName",value = "用户名",required = true,paramType = "String"),
    })
    @Transactional(rollbackFor = Exception.class)
    public ResultVO getGoodsAddressByIdAndUserName(@RequestParam("id")Integer id,@RequestParam("userName")String userName){
        return addressService.getGoodsAddressByIdAndUserName(id,userName);
    }

}
